//
//  MYCardTableViewController.m
//  投融保
//
//  Created by 523 on 13-12-20.
//  Copyright (c) 2013年 木叶科技. All rights reserved.
//

#import "MYCardTableViewController.h"
#import "MYAgreementViewController.h"
#import "MYBankCell.h"
#import "UIImageView+WebCache.h"

@interface MYCardTableViewController ()

@end

@implementation MYCardTableViewController
@synthesize myCardTable;
@synthesize arrCards;

extern NSDictionary *userInformation ;//用户信息
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent  animated:YES];
    [self.view setBackgroundColor:[UIColor clearColor]];
//    [UIApplication sharedApplication].delegate.widow.frame = CGRectMake(0, 20, 758, 456);
    
    //初始化银行信息
    self.arrCards=[[NSMutableArray alloc] init];
    NSMutableDictionary *dictBankInfo=[NSMutableDictionary new];
    if ([userInformation valueForKey:@"bankName"]) {
        [dictBankInfo setValue:[userInformation valueForKey:@"banklog"] forKey:@"banklog"];
        [dictBankInfo setValue:[userInformation valueForKey:@"bankName"] forKey:@"bankName"];
        [dictBankInfo setValue:[userInformation valueForKey:@"bankCardNo"] forKey:@"bankCardNo"];
        [dictBankInfo setValue:[userInformation valueForKey:@"bankType"] forKey:@"bankType"];
        
        [self.arrCards addObject:dictBankInfo];
    }
    
    
    SETBACKGROUND
    
    
    
    [self initView];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initView
{
    Y=0;
    if (IOS_VERSION>=7) {
        Y=20;
    }
    
    
    
    //导航视图
    UIView *titleView=[[UIView alloc] initWithFrame:CGRectMake(0, Y, SCREEN_WIDTH, 104)];
    [titleView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"titile_bg"]]];
    [self.view addSubview:titleView];
    
    UILabel *lblTitle=[[UILabel alloc] initWithFrame:CGRectMake(284, 12, 200, 80)];
    [lblTitle setText:@"我的银行卡"];
    [lblTitle setTextColor:[UIColor whiteColor]];
    [lblTitle setFont:[UIFont boldSystemFontOfSize:40]];
    lblTitle.backgroundColor=[UIColor clearColor];
    lblTitle.textAlignment=NSTextAlignmentCenter;
    [titleView addSubview:lblTitle];
    
    
    UIButton *btnReturn=[UIButton new];
    [btnReturn setFrame:CGRectMake(0, 0, 105, 105)];
    [btnReturn setImage:[UIImage imageNamed:@"return_icon"] forState:UIControlStateNormal];
    [btnReturn.titleLabel setFont:[UIFont systemFontOfSize:22]];
    [btnReturn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnReturn addTarget:self action:@selector(btnReturnClick) forControlEvents:UIControlEventTouchUpInside];
    [titleView addSubview: btnReturn];
    
    
    self.myCardTable=[[UITableView alloc] initWithFrame:CGRectMake(50, Y+140, 668, 145)];
    [self.myCardTable.layer setCornerRadius:20.0f];
    [self.myCardTable setBackgroundColor:[UIColor whiteColor]];
    [self.myCardTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.myCardTable.delegate=self;
    self.myCardTable.dataSource=self;
    self.myCardTable.scrollEnabled=NO;
    [self.view addSubview:self.myCardTable];
    
    // 设置myCardTable边框
    [[self.myCardTable layer] setBorderWidth:0.5f];
    [[self.myCardTable layer] setBorderColor:[UIColor lightGrayColor].CGColor];
    
    
    UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(50, self.myCardTable.frame.size.height+self.myCardTable.frame.origin.y+60, 668, 88)];
    
    [button setTitle:@"重新邦卡" forState:UIControlStateNormal];
    button.titleLabel.font=[UIFont boldSystemFontOfSize:35];
    [button setBackgroundImage:[UIImage imageNamed:@"login_bg"] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(btnCard) forControlEvents:UIControlEventTouchUpInside];
    
    if (self.arrCards.count>0) {
        [self.view addSubview:button];
        
    }
    
    
}

//返回前页按钮方法
- (void)btnReturnClick
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

//添加银行按钮事件
- (void)btnCard
{
    MYAgreementViewController *agreementVC=[MYAgreementViewController new];
    [self presentViewController:agreementVC animated:YES completion:nil];
}

#pragma mark   +++++++++++++tableView 代理++++++++++++++


- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier=@"reuserIdentifier";
    MYBankCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell==nil) {
        NSArray *arrCell=[[NSBundle mainBundle] loadNibNamed:@"MYBankCell" owner:self options:nil];
        cell= [arrCell objectAtIndex:0];
    }
    [cell.imageBank setImageWithURL:[NSURL URLWithString:[[arrCards objectAtIndex:indexPath.row] valueForKey:@"banklog"]] placeholderImage:nil];
    //设置背景
    
    cell.lblTailNumber.text = [[arrCards objectAtIndex:indexPath.row] valueForKey:@"bankCardNo"];
    [cell setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell_bg"]]];
    
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    
    return cell;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    //背景图
    UIImageView *imageCardInfo=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 668, 145)];
    imageCardInfo.image=[UIImage imageNamed:@"light_gray_bg"];
    
    //添加银行卡按钮
    UIButton *btnAddCard=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 668, 145)];
    [btnAddCard setTitle:@"添加银行卡" forState:UIControlStateNormal];
    btnAddCard.titleLabel.font=[UIFont boldSystemFontOfSize:35];
    [btnAddCard setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btnAddCard addTarget:self action:@selector(btnCard) forControlEvents:UIControlEventTouchUpInside];
    [btnAddCard setBackgroundColor:[UIColor clearColor]];
    [imageCardInfo addSubview:btnAddCard];
    
    imageCardInfo.userInteractionEnabled=YES;
    return imageCardInfo;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 145;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (self.arrCards.count>0) {
        return 0;
    }
    else
    {
        return 145;
    }
}

#pragma mark-   -----------状态栏底色------
- (UIStatusBarStyle)preferredStatusBarStyle
{
    [self.view setBackgroundColor:[UIColor blackColor]];
    return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden
{
    return NO;
}


@end
